// pages/order/insuranceOrder/insuranceOrder.js
const app = getApp();
const util = require('../../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    quotationId: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.request('/Order/QuotationDetailForInsurance', 'GET', { insuranceId: options.quotationId }, res => {
      this.setData({
        quotationId: options.quotationId,
        carPhoto: res.quotationCarModel.carPhoto,
        licencePlate: res.quotationCarModel.licencePlate,
        quotationNumber: res.insuranceQuotation.quotationNumber,
        createTime: util.formatTime(res.insuranceQuotation.createTime),
        applicantName: res.insuranceQuotation.applicantName,
        applicantPhoneNumber: res.insuranceQuotation.applicantPhoneNumber,
        applicantIdentityCard: res.insuranceQuotation.applicantIdentityCard,
        insuranceFirstBeneficiary: res.insuranceQuotation.insuranceFirstBeneficiary,
        ifTransferAfterFirstInsure: res.insuranceQuotation.ifTransferAfterFirstInsure === 1 ? '是' : '否',
        insureArea: res.insuranceQuotation.insureArea,
        insuranceQuotationDetail: res.insuranceQuotationDetail,
        quotationStatus: res.insuranceQuotation.quotationStatus,
        quotationStatusName: res.insuranceQuotation.quotationStatusName
      });
    });
  },
  /**
   * 点击取消报价单
   */
  cancelFn() {
    wx.showModal({
      title: '取消报价单',
      content: '确定要取消此保险报价单吗？',
      success: res => {
        if (res.confirm) {
          app.request('/Order/CancelQuotation', 'DELETE', {
            userId: app.globalData.userId,
            quotationType: 1,
            quotationId: this.data.quotationId
          }, res => {
            wx.showToast({ title: '取消成功', icon: 'none', duration: 2000 });
            var pages = getCurrentPages(); // 当前页面
            var beforePage = pages[pages.length - 2]; // 前一个页面
            beforePage.getData('update');
            wx.navigateBack({ delta: 1 });
          });
        }
      }
    });
  }
})